package com.hainatong.jcmvvmbase.mainhome;

import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import com.blankj.utilcode.util.SPUtils;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.hainatong.jcmvvmbase.Constants;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.ActivitySplashViewBinding;
import com.hainatong.jcmvvmbase.login.LoginActivity;
import com.hainatong.mvvmbase.base.BaseMvvmActivity;
import com.hainatong.mvvmbase.base.NoViewModel;

public class SplashActivity extends BaseMvvmActivity<ActivitySplashViewBinding , NoViewModel>
{
    private Animation alphaAnim;
    @Override
    protected int getLayoutId()
    {
        return R.layout.activity_splash_view;
    }

    @Override
    protected int getBindingVariable() {
        return 0;
    }

    @Override
    protected void initView()
    {
        //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        ImmersionBar.with(this)
                    .hideBar(BarHide.FLAG_HIDE_BAR)
                    .init();


        alphaAnim = AnimationUtils.loadAnimation(this,R.anim.anim_launch_item_scale_in);

        alphaAnim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation)
            {

            }

            @Override
            public void onAnimationEnd(Animation animation)
            {
                // 如果用户登录了
                String authToken = SPUtils.getInstance(Constants.CONFIG).getString("Token","");
                if (TextUtils.isEmpty(authToken))
                {
                    LoginActivity.start(SplashActivity.this);
                }
                else
                {
                    LoginActivity.start(SplashActivity.this);
                }
                SplashActivity.this.finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation)
            {

            }
        });
        viewDataBinding.applogo.setVisibility(View.VISIBLE);
        viewDataBinding.applogo.startAnimation(alphaAnim);

    }

    @Override
    protected void initData()
    {

    }

    @Override
    protected void onRetryBtnClick()
    {

    }
}
